#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>

int main(){
        char* filename = "mytesti.txt";
        char buf[1024] = {0};
        int fd = open(filename,O_RDONLY);
        if (fd == -1){
                perror("open file 1 err");
                exit(1);
        }
        printf("fd = %d,errno=%d,message=%s\n",fd,errno,strerror(errno));
        int count = 0;
        int fd2 = open("mytest1.txt",O_CREAT|O_RDWR,0664);
        while((count = read(fd,buf,1024))!=0){ //0 读取完成 
                printf("%s",buf);
                write(fd2,buf,count);
        }
        printf("\n");
        close(fd);
        close(fd2);
        return 0;
}